//
//  SelectScreenView.m
//  宜居HD
//
//  Created by 张金国 on 16/4/28.
//  Copyright © 2016年 张金国. All rights reserved.
//

#import "SelectScreenView.h"
#import "TitleView.h"
#import "Masonry.h"
#import "BigButton.h"
#import "UIColor+RandomColor.h"
#import "Macro.h"


@interface SelectScreenView ()

@property (nonatomic, strong)TitleView *titleView;

@end

@implementation SelectScreenView

#pragma mark - init
- (instancetype)initWithHandleButtonEventBlock:(HandleButtonEventBlock)handleButtonEventBlock {
    if (self = [super init]) {
        self.handleButtonEventBlock = handleButtonEventBlock;
        [self setupConstraints];
    }
    return self;
}

#pragma mark - Private
- (void)setupConstraints {
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(self).offset(10);
        make.height.equalTo(self.mas_height).multipliedBy(1/4.0f);
        make.width.equalTo(self.mas_width).multipliedBy(1/4.0f);
    }];
    
    BigButton *tempbutton = nil;
    for (int i = 0; i < 4; i++) {
        BigButton *button1 = [[BigButton alloc] init];
        button1.backgroundColor = kSandboxieVcBkColor;
        button1.buttontype = BigButtonTypeNormal;
        button1.heightPercent = 0.8; //图标和label占高度百分百
        button1.titleLabel.textColor = [UIColor randomColor];
        button1.image = [UIImage imageNamed:@"Computer"];
        button1.tag = i ;
        button1.title = @"默认状态";
        [button1 addTarget:self action:@selector(handleButtonEvent:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:button1];
        
        if (tempbutton == nil) {
            [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleView.mas_bottom);
                make.left.equalTo(self.mas_left).offset(SCREEN_WIDTH/2-260);
                make.width.height.equalTo(self.mas_height).multipliedBy(1.2/2.0f);
            }];
            
        }else {
            [button1 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self.titleView.mas_bottom);
                make.left.equalTo(tempbutton.mas_right).offset(20);
                make.width.height.equalTo(self.mas_height).multipliedBy(1.2/2.0f);
            }];
        }
        tempbutton = button1;
    }

}

#pragma mark - Event response
- (void)handleButtonEvent:(UIButton *)button {
    SelcetScreenType selcetScreenType = button.tag;
    self.handleButtonEventBlock(selcetScreenType);
}

#pragma mark - getter
- (TitleView *)titleView {
    if (!_titleView) {
        _titleView = [[TitleView alloc]initWithLineColor:[UIColor redColor] title:@"请选择显示器" titleFont:kLabelTextColor];
        [self addSubview:_titleView];
    }
    return _titleView;
}


@end
